#ifndef _CGRIP_H_
#define _CGRIP_H_

#include <buola/widgets/cwidget.h>

#include <buola/utility/uevent.h>

namespace buola { namespace gui {

class CGrip : public CWidget
{
public:
    CGrip();
    ~CGrip();

protected:
    void CalcPos();
    void UpdatePointer(const CPoint_d&);
    int HitTest(const CPoint_d&);

public:
////////////// Event handling //////////////
    virtual void OnExpose(const CExposeEvent &pE);
    virtual void OnButtonDown(const CMouseEvent &pE);
    virtual void OnButtonUp(const CMouseEvent &pE);
    virtual void OnMouseMove(const CMouseEvent &pE);
    virtual void OnMouseOut(const CMouseEvent &pE);
    virtual void OnMouseIn(const CMouseEvent &pE);
    virtual void OnFocusIn(const CFocusEvent &pE);
    virtual void OnFocusOut(const CFocusEvent &pE);
    virtual void OnKeyDown(const CKeyEvent &pE);
    virtual void OnKeyUp(const CKeyEvent &pE);
    virtual void OnStyleChanged(TStyle);
    virtual void OnSize(const CGeometryEvent &pE);
    virtual void OnMove(const CGeometryEvent &pE);

    UEvent<void(CPoint_d,CSize_d,EKeyMod)> eMoved;

protected:
    CPoint_d mPos[8];

    CPointer::EStock mPointer;

    bool mPosIsValid;

    bool mDragging;
    CPoint_d mDragPos;
    int mDragType;

    static img::CPicture mGrip;
};

/*namespace gui*/ } /*namespace buola*/ }

#endif
